package com.example.peibei.ui.activity;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dingtao.common.bean.GetOrderDetail;
import com.dingtao.common.bean.HomeBannerCate;
import com.dingtao.common.bean.OrderDetail;
import com.dingtao.common.bean.WeekTimeBean;
import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.core.exception.ApiException;
import com.dingtao.common.util.GlideUtils;
import com.dingtao.common.util.SPUtils;
import com.dingtao.common.util.UIUtils;
import com.example.peibei.R;
import com.example.peibei.base.Constant;
import com.example.peibei.base.SpConstant;
import com.example.peibei.service.presenter.ChcekTextPresenter;
import com.example.peibei.service.presenter.EditOrderPresenter;
import com.example.peibei.service.presenter.GetOrderDetailPresenter;
import com.example.peibei.service.presenter.OrderDetailPresenter;
import com.example.peibei.service.presenter.UploadImagePresenter;
import com.example.peibei.ui.adapter.ChooseWeekTimeAdapter;
import com.example.peibei.ui.adapter.EditOrderImgsAdapter;
import com.example.peibei.ui.adapter.WeekTimeAdapter;
import com.example.peibei.ui.weight.GlideEngine;
import com.example.peibei.ui.weight.MoneyKeyboardDialog;
import com.linxiao.framework.common.ScreenUtil;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.yxp.permission.util.lib.PermissionUtil;
import com.yxp.permission.util.lib.callback.PermissionResultCallBack;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.addapp.pickers.listeners.OnMoreItemPickListener;
import cn.addapp.pickers.listeners.OnMoreWheelListener;
import cn.addapp.pickers.picker.LinkagePicker;
import cn.addapp.pickers.picker.SinglePicker;

public class EditOrderActivity extends WDActivity implements SeekBar.OnSeekBarChangeListener {
    @BindView(R.id.tv_dec)
    TextView tv_dec;
    @BindView(R.id.et_money)
    EditText et_money;
    @BindView(R.id.iv_img_one)
    ImageView iv_img_one;
    @BindView(R.id.iv_img_two)
    ImageView iv_img_two;
    @BindView(R.id.iv_img_three)
    ImageView iv_img_three;
    @BindView(R.id.ll_imgs)
    LinearLayout ll_imgs;
    @BindView(R.id.rb_set_age)
    RadioButton rb_set_age;
    @BindView(R.id.seek_bar)
    SeekBar seek_bar;
    @BindView(R.id.tv_max)
    TextView tv_max;
    @BindView(R.id.rg_gender)
    RadioGroup rg_gender;
    @BindView(R.id.rv_week_time)
    RecyclerView rv_week_time;
    @BindView(R.id.ll_add_week)
    LinearLayout ll_add_week;
    @BindView(R.id.rb_set_sex)
    RadioButton rb_set_sex;
    @BindView(R.id.rb_male)
    RadioButton rb_male;
    @BindView(R.id.rb_female)
    RadioButton rb_female;
    @BindView(R.id.rl_edit_money)
    RelativeLayout rl_edit_money;
    @BindView(R.id.rl_edit_money_right)
    RelativeLayout rl_edit_money_right;
    @BindView(R.id.rv_choose_time)
    RecyclerView rv_choose_time;
    @BindView(R.id.iv_close_one)
    ImageView iv_close_one;
    @BindView(R.id.iv_close_two)
    ImageView iv_close_two;
    @BindView(R.id.iv_close_three)
    ImageView iv_close_three;
    @BindView(R.id.rl_img_one)
    RelativeLayout rl_img_one;
    @BindView(R.id.rl_img_two)
    RelativeLayout rl_img_two;
    @BindView(R.id.rl_img_three)
    RelativeLayout rl_img_three;
    @BindView(R.id.rv_imgs)
    RecyclerView rv_imgs;
    @BindView(R.id.tv_city_name)
    TextView tv_city_name;
    @BindView(R.id.rb_yikoujia)
    RadioButton rb_yikoujia;
    @BindView(R.id.rd_xiaoshi)
    RadioButton rd_xiaoshi;
    @BindView(R.id.tv_money)
    TextView tv_money;

    private String orderId;
    private SPUtils spUtils;
    private String token;
    private int mixAge = 18;
    private int maxAge = 60;
    private int chooseAge;
    List<WeekTimeBean> weekTimes = new ArrayList<>();
    List<WeekTimeBean> weeks = new ArrayList<>();
    private WeekTimeAdapter weekTimeAdapter;
    private int week = 1;
    private String weekName = "周一";
    private String startTime = "00:00";
    private String endTime = "24:00";
    private String gender = "0";
    private String timeLimit = "1_00:00-23:00";
    private EditOrderPresenter editOrderPresenter;
    private String ageLimit;
    private List<String> imgs = new ArrayList<>();
    private ChcekTextPresenter chcekTextPresenter;
    private String content;
    String imagePathOne = "";
    String imagePathTwo = "";
    String imagePathThree = "";
    private String unit;

    private ChooseWeekTimeAdapter chooseWeekTimeAdapter;
    private UploadImagePresenter uploadImagePresenter;
    private EditOrderImgsAdapter editOrderImgsAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_edit_order;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        orderId = bundle.getString("orderId");
        spUtils = new SPUtils(EditOrderActivity.this, SpConstant.USER_TOKEN);
        token = spUtils.getString(SpConstant.USER_TOKEN);
        OrderDetailPresenter orderDetailPresenter = new OrderDetailPresenter(new OrderCall());
        editOrderPresenter = new EditOrderPresenter(new EditCall());
        chcekTextPresenter = new ChcekTextPresenter(new CheckTextCall());
        uploadImagePresenter = new UploadImagePresenter(new UploadCall());
        orderDetailPresenter.reqeust(orderId, "Bearer " + token);
        seek_bar.setOnSeekBarChangeListener(this);
        getWeeks();
        rv_week_time.setLayoutManager(new LinearLayoutManager(this));
        weekTimeAdapter = new WeekTimeAdapter(weekTimes);
        rv_week_time.setAdapter(weekTimeAdapter);
        weekTimeAdapter.addChildClickViewIds(R.id.rb_week, R.id.ll_week_time, R.id.ll_week_time_no);

        rv_choose_time.setLayoutManager(new LinearLayoutManager(this));
        chooseWeekTimeAdapter = new ChooseWeekTimeAdapter(weekTimes);
        rv_choose_time.setAdapter(chooseWeekTimeAdapter);
        chooseWeekTimeAdapter.addChildClickViewIds(R.id.ll_week_time);

        rv_imgs.setLayoutManager(new GridLayoutManager(this, 3));
        editOrderImgsAdapter = new EditOrderImgsAdapter(imgs);
        rv_imgs.setAdapter(editOrderImgsAdapter);
        editOrderImgsAdapter.addChildClickViewIds(R.id.iv_close_one);
        editOrderImgsAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                if (view.getId() == R.id.iv_close_one) {
                    imgs.remove(position);
                    editOrderImgsAdapter.notifyDataSetChanged();
                }
            }
        });

        chooseWeekTimeAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                if (view.getId() == R.id.ll_week_time) {
                    showChooseTime(position);
                }
            }
        });
        chooseWeekTimeAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                weekTimes.get(position).setChoosed(!weekTimes.get(position).isChoosed());
                chooseWeekTimeAdapter.notifyDataSetChanged();
            }
        });

        weekTimeAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            if (view.getId() == R.id.rb_week) {
                showChooseWeek(position);
            } else {
                showChooseTime(position);
            }
        });
        rg_gender.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.rb_set_sex) {
                gender = "0";
            } else if (checkedId == R.id.rb_male) {
                gender = "1";
            } else {
                gender = "2";
            }
        });
        rl_edit_money.setOnClickListener(v -> {
            String money = et_money.getText().toString().trim();
            double i;
            if (!money.equals("")) {
                double v1 = Double.parseDouble(money);
                if (v1 > 1) {
                    i = v1 - 1;
                    et_money.setText(i + "");
                }
            }
        });
        rl_edit_money_right.setOnClickListener(v -> {
            String money = et_money.getText().toString().trim();
            double i;
            if (!money.equals("")) {
                double v1 = Double.parseDouble(money);
//                int integer = Integer.parseInt(money);
                i = v1 + 1;
                et_money.setText(i + "");
            }
        });
        rb_set_age.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                seek_bar.setProgress(100);
            }
        });
        ll_add_week.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addWeekTime();
            }
        });

        CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    compoundButton.setTextColor(Color.WHITE);
                } else {
                    compoundButton.setTextColor(Color.BLACK);
                }
                if (compoundButton == rb_yikoujia){
                    if (b){
                        unit = "-1";
                    }
                }else if (compoundButton == rd_xiaoshi){
                    if (b){
                        unit = "0";
                    }
                }
            }
        };
        rb_yikoujia.setChecked(true);
        rb_yikoujia.setOnCheckedChangeListener(onCheckedChangeListener);
        rd_xiaoshi.setOnCheckedChangeListener(onCheckedChangeListener);
    }
    @OnClick(R.id.layout_set_money)
    public void setMoney(){
        MoneyKeyboardDialog dialog = new MoneyKeyboardDialog(this);
        dialog.create(new MoneyKeyboardDialog.OnMoneyListener() {
            @Override
            public void onMoney(String money) {
                tv_money.setText(money);
            }
        });
    }

    private void addWeekTime() {
        if (weekTimes.size() < 7) {
            weekTimes.add(new WeekTimeBean(1, "00:00", "23:00", "周一"));
            weekTimeAdapter.notifyDataSetChanged();
        }
    }

    @OnClick(R.id.iv_back)
    public void back() {
        finish();
    }

    @OnClick(R.id.rl_add_one)
    public void addImage() {
        if (imgs.size() > 2) {
            UIUtils.showToastSafe("最多添加三张图片哦");
        } else {
            showChooseImageDialog();
        }
    }

    private void showChooseImageDialog() {
//        PictureSelector
//                .create(EditOrderActivity.this, PictureSelector.SELECT_REQUEST_CODE)
//                .selectPicture(true);
        getPermission();
    }

    private static String[] PERMISSIONS = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.CAMERA
    };

    private void getPermission() {
        PermissionUtil.getInstance().request(this, PERMISSIONS,
                new PermissionResultCallBack() {
                    @Override
                    public void onPermissionGranted() {
                        showAlbum();
                    }

                    @Override
                    public void onPermissionGranted(String... strings) {
                        // 当所有权限的申请被用户同意之后,该方法会被调用
                        //get_NovelUrl(id);
                    }

                    @Override
                    public void onPermissionDenied(String... permissions) {

                        UIUtils.showToastSafe("部分权限被禁止需要手动开启");

                        // 当权限申请中的某一个或多个权限,被用户曾经否定了,并确认了不再提醒时,也就是权限的申请窗口不能再弹出时,该方法将会被调用
                        getPermission();
                    }

                    @Override
                    public void onRationalShow(String... permissions) {
                        UIUtils.showToastSafe("部分权限被禁止需要手动开启");
                        // 当权限申请中的某一个或多个权限,被用户否定了,但没有确认不再提醒时,也就是权限窗口申请时,但被否定了之后,该方法将会被调用.
                        getPermission();
                    }

                });
    }

    private void showAlbum() {
        PictureSelector.create(EditOrderActivity.this)
                .openGallery(PictureMimeType.ofImage())
                .loadImageEngine(GlideEngine.createGlideEngine())
                .maxSelectNum(1)
                .minSelectNum(1)
                .compress(true)
                .selectionMode(PictureConfig.SINGLE)
                .forResult(PictureConfig.CHOOSE_REQUEST);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /*结果回调*/
        /*结果回调*/
        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            if (data != null) {
                List<LocalMedia> localMedia = PictureSelector.obtainMultipleResult(data);
                uploadImage(localMedia.get(0).getCompressPath());
            }
        }
//        if (requestCode == PictureSelector.SELECT_REQUEST_CODE) {
//            if (data != null) {
//                PictureBean pictureBean = data.getParcelableExtra(PictureSelector.PICTURE_RESULT);
//                uploadImage(pictureBean.getPath());
//            }
//        }
    }

    private void uploadImage(String imagePath) {
//        if (imgs.size() == 0) {
//            iv_close_one.setVisibility(View.VISIBLE);
//            rl_img_one.setVisibility(View.VISIBLE);
//            iv_img_one.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//        } else if (imgs.size() == 1) {
//            if (rl_img_one.getVisibility() == View.GONE) {
//                iv_close_one.setVisibility(View.VISIBLE);
//                rl_img_one.setVisibility(View.VISIBLE);
//                iv_img_one.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//            } else {
//                rl_img_two.setVisibility(View.VISIBLE);
//                iv_close_two.setVisibility(View.VISIBLE);
//                iv_img_two.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//            }
//        } else {
//            if (rl_img_one.getVisibility() == View.GONE) {
//                rl_img_one.setVisibility(View.VISIBLE);
//                iv_close_one.setVisibility(View.VISIBLE);
//                iv_img_one.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//            } else if (rl_img_two.getVisibility() == View.GONE) {
//                rl_img_two.setVisibility(View.VISIBLE);
//                iv_close_two.setVisibility(View.VISIBLE);
//                iv_img_two.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//            } else {
//                rl_img_three.setVisibility(View.VISIBLE);
//                iv_close_three.setVisibility(View.VISIBLE);
//                iv_img_three.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//            }
//        }
        uploadImagePresenter.reqeust(imagePath, "Bearer " + token);
    }

    private Bitmap compressQuality(Bitmap bitmap) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 30, bos);
        byte[] bytes = bos.toByteArray();
        Log.e("bitmapsize", String.valueOf(bytes.length));
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    }

    class UploadCall implements DataCall<String> {

        @Override
        public void success(String data, Object... args) {
            imgs.add("https://resource.quqdan.com/" + data);
            editOrderImgsAdapter.notifyDataSetChanged();
            Log.i("answer", "图片上传成功：" + data);
        }

        @Override
        public void fail(ApiException e, Object... args) {
            UIUtils.showToastSafe("您的输入含有不合法的内容或图片，请遵守用户协议相关内容");
        }
    }

    @OnClick(R.id.tv_send_edit)
    public void sendEdit() {
        content = tv_dec.getText().toString().trim();
        if (content.equals("")) {
            UIUtils.showToastSafe("内容不能为空");
            return;
        }
        chcekTextPresenter.reqeust("Bearer " + token, content);
    }

    class EditCall implements DataCall<HomeBannerCate> {

        @Override
        public void success(HomeBannerCate data, Object... args) {
            UIUtils.showToastSafe("修改成功");
            finish();
        }

        @Override
        public void fail(ApiException e, Object... args) {
            UIUtils.showToastSafe(e.getDisplayMessage());
        }

    }

    class CheckTextCall implements DataCall<String> {

        @Override
        public void success(String data, Object... args) {
            String money = tv_money.getText().toString().trim();
            if (TextUtils.isEmpty(money)) {
                UIUtils.showToastSafe("金额不能为空");
                return;
            }
            if (imgs.size() < 1) {
                UIUtils.showToastSafe("请至少上传一张图片");
                return;
            }
            StringBuilder str = new StringBuilder();
            for (int i = 0; i < weekTimes.size(); i++) {
                if (weekTimes.get(i).isChoosed()) {
                    if (i == weekTimes.size() - 1) {
                        str.append(weekTimes.get(i).getWeek() + "_" + weekTimes.get(i).getStartTime() + "-" + weekTimes.get(i).getEndTime());
                    } else {
                        str.append(weekTimes.get(i).getWeek() + "_" + weekTimes.get(i).getStartTime() + "-" + weekTimes.get(i).getEndTime());
                        str.append(",");
                    }
                }
            }
            timeLimit = str.toString();
            StringBuilder str2 = new StringBuilder();
            for (int j = 0; j < imgs.size(); j++) {
                if (j == imgs.size() - 1) {
                    str2.append(imgs.get(j));
                } else {
                    str2.append(imgs.get(j));
                    str2.append(",");
                }
            }
            editOrderPresenter.reqeust("Bearer " + token, orderId, ageLimit, gender, str2.toString(), content, money, timeLimit,unit);
        }

        @Override
        public void fail(ApiException e, Object... args) {
            UIUtils.showToastSafe("您的输入含有不合法的内容或图片，请遵守用户协议相关内容");
        }

    }

    class OrderCall implements DataCall<OrderDetail> {

        @Override
        public void success(OrderDetail data, Object... args) {
            if (data != null) {
                unit = data.getUnit();
                if ("-1".equals(unit)){
                    rb_yikoujia.setChecked(true);
                }else {
                    rd_xiaoshi.setChecked(true);
                }
                tv_dec.setText(data.getOtherDesc());
                et_money.setText(data.getPrice());
                imgs.clear();
                imgs.addAll(data.getImgs());
                editOrderImgsAdapter.notifyDataSetChanged();
                tv_city_name.setText(data.getArea());
//                imgs = data.getImgs();
//                if (imgs.size() > 0) {
//                    if (imgs.get(0) != null && !TextUtils.isEmpty(imgs.get(0))) {
//                        GlideUtils.loadImg(EditOrderActivity.this, imgs.get(0), 20, iv_img_one);
//                        iv_close_one.setVisibility(View.VISIBLE);
//                        iv_close_one.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                imgs.remove(0);
//                                rl_img_one.setVisibility(View.GONE);
//                            }
//                        });
//                    }
//                    if (imgs.size() > 1) {
//                        if (imgs.get(1) != null && !TextUtils.isEmpty(imgs.get(1))) {
//                            GlideUtils.loadImg(EditOrderActivity.this, imgs.get(1), 20, iv_img_two);
//                            iv_close_two.setVisibility(View.VISIBLE);
//                            iv_close_two.setOnClickListener(new View.OnClickListener() {
//                                @Override
//                                public void onClick(View v) {
////                                    if (imgs.size() > 1) {
//                                    imgs.remove(1);
//                                    rl_img_two.setVisibility(View.GONE);
//                                }
//                            });
//                        }
//                    }
//                    if (imgs.size() > 2) {
//                        if (imgs.get(2) != null && !TextUtils.isEmpty(imgs.get(2))) {
//                            GlideUtils.loadImg(EditOrderActivity.this, imgs.get(2), 20, iv_img_three);
//                            iv_close_three.setVisibility(View.VISIBLE);
//                            iv_close_three.setOnClickListener(new View.OnClickListener() {
//                                @Override
//                                public void onClick(View v) {
//                                    imgs.remove(2);
//                                    rl_img_three.setVisibility(View.GONE);
//                                }
//                            });
//                        }
//                    }
//                }
                ageLimit = data.getAgeLimit();
                if (ageLimit.equals("不限")) {
                    rb_set_age.setChecked(true);
                    seek_bar.setProgress(100);
                    tv_max.setText("60");
                }
                gender = data.getGender();
                if (gender.equals("0")) {
                    rb_female.setChecked(true);
                } else if (gender.equals("1")) {
                    rb_male.setChecked(true);
                } else {
                    rb_set_sex.setChecked(true);
                }
                List<OrderDetail.TimeDTO> time = data.getTime();
                for (int i = 0; i < time.size(); i++) {
                    String time1 = time.get(i).getTime();
                    String[] split = time1.split("-");
                    WeekTimeBean weekTimeBean = new WeekTimeBean(Integer.parseInt(time.get(i).getWeek()), split[0], split[1], time.get(i).getTips());
                    weekTimeBean.setChoosed(true);
                    weekTimes.add(weekTimeBean);
                }
//                weekTimeAdapter.notifyDataSetChanged();
                chooseWeekTimeAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void fail(ApiException e, Object... args) {
        }
    }

    private void getWeeks() {
        weeks.add(new WeekTimeBean(1, "", "", "周一"));
        weeks.add(new WeekTimeBean(2, "", "", "周二"));
        weeks.add(new WeekTimeBean(3, "", "", "周三"));
        weeks.add(new WeekTimeBean(4, "", "", "周四"));
        weeks.add(new WeekTimeBean(5, "", "", "周五"));
        weeks.add(new WeekTimeBean(6, "", "", "周六"));
        weeks.add(new WeekTimeBean(7, "", "", "周日"));
    }

    private void showChooseWeek(int position) {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < weeks.size(); i++) {
            list.add(weeks.get(i).getWeekName());
        }
        SinglePicker<String> picker = new SinglePicker<>(this, list);
        picker.setCanLoop(false);//不禁用循环
        picker.setLineVisible(true);
        picker.setTextSize(16);
        picker.setSelectedIndex(0);
        picker.setItemWidth(200);
        picker.setTextSize(18);
        picker.setOuterLabelEnable(true);
        picker.setGravity(Gravity.BOTTOM);
        picker.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        picker.setHeight(ScreenUtil.getRealScreenWidth());
        picker.setLineColor(ContextCompat.getColor(this, R.color.color_EEEEEE));
        picker.setSelectedTextColor(ContextCompat.getColor(this, R.color.text_dark_gray));//前四位值是透明度
        picker.setUnSelectedTextColor(ContextCompat.getColor(this, R.color.color_9C9DA1));
        picker.getWindow().setBackgroundDrawableResource(R.drawable.shape_white_bg);
        picker.setOnSingleWheelListener((index, item) -> {
            week = index + 1;
            weekName = item;
        });
        picker.setOnItemPickListener((index, item) -> {
            week = index + 1;
            weekName = item;
            weekTimes.get(position).setWeek(week);
            weekTimes.get(position).setWeekName(weekName);
            weekTimeAdapter.notifyDataSetChanged();
        });
        picker.show();
    }

    private void showChooseTime(int position) {
        LinkagePicker.DataProvider provider = new LinkagePicker.DataProvider() {

            @Override
            public boolean isOnlyTwo() {
                return true;
            }

            @Override
            public List<String> provideFirstData() {
                return Arrays.asList(Constant.times);
            }

            @Override
            public List<String> provideSecondData(int firstIndex) {
                return Arrays.asList(Constant.times);
            }

            @Override
            public List<String> provideThirdData(int firstIndex, int secondIndex) {
                return null;
            }

        };
        LinkagePicker picker = new LinkagePicker(this, provider);
        Window window = picker.getWindow();
        if (window != null) {
//            window.setGravity(Gravity.BOTTOM);
            ////解决宽度问题
            window.setGravity(Gravity.BOTTOM);
            WindowManager.LayoutParams params = window.getAttributes();
            params.width = ViewGroup.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            window.setAttributes(params);
            window.setBackgroundDrawableResource(R.drawable.shape_white_bg);
        }
        picker.setTextSize(18);
        picker.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        picker.setHeight(ScreenUtil.getRealScreenWidth());
        picker.setCanLoop(false);
        picker.setSelectedIndex(0, 23);
        picker.setGravity(Gravity.BOTTOM);
        picker.setLineColor(ContextCompat.getColor(this, R.color.color_EEEEEE));
        picker.setSelectedTextColor(ContextCompat.getColor(this, R.color.text_dark_gray));//前四位值是透明度
        picker.setUnSelectedTextColor(ContextCompat.getColor(this, R.color.color_9C9DA1));
        picker.setOnMoreWheelListener(new OnMoreWheelListener() {
            @Override
            public void onFirstWheeled(int index, String item) {
                startTime = item;
            }

            @Override
            public void onSecondWheeled(int index, String item) {
                endTime = item;
            }

            @Override
            public void onThirdWheeled(int index, String item) {

            }
        });
        picker.setOnMoreItemPickListener((OnMoreItemPickListener<String>) (first, second, third) -> {
            startTime = first;
            endTime = second;
            String[] split = startTime.split(":");
            String[] split1 = endTime.split(":");
            String a = split[0];
            String b = split1[0];
            int i = Integer.parseInt(a);
            int i1 = Integer.parseInt(b);
            if (i > i1) {
                UIUtils.showToastSafe("开始时间不能超过结束时间，请重新选择");
            } else {
                weekTimes.get(position).setStartTime(startTime);
                weekTimes.get(position).setEndTime(endTime);
                chooseWeekTimeAdapter.notifyDataSetChanged();
            }
        });
        picker.show();
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        chooseAge = mixAge + progress;
        tv_max.setText(chooseAge + "");
        if (chooseAge < maxAge) {
            rb_set_age.setChecked(false);
            ageLimit = chooseAge + "";
        } else {
            rb_set_age.setChecked(true);
            ageLimit = "不限";
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    protected void destoryData() {

    }
}
